
#ifndef JELLY_SHARE_SRC_UTILITY_CONVERSION_H_
#define JELLY_SHARE_SRC_UTILITY_CONVERSION_H_

#include <string>
#include "libiconv/include/iconv.h"
#include "src/error_code.h"
#include "boost/lexical_cast.hpp"   



namespace jellyfish
{
	namespace utility
	{
		//std::wstring string_to_wstring(const std::string& s)
		//{
		//	std::wstring temp(s.length(),L' ');
		//	std::copy(s.begin(), s.end(), temp.begin());
		//	return temp; 
		//}

		//std::string wstring_to_string(const std::wstring& s)
		//{
		//	std::string temp(s.length(), ' ');
		//	std::copy(s.begin(), s.end(), temp.begin());
		//	return temp; 
		//}

		//int32_t change_code( const char* from_code,const char* to_code,const char* in,
		//				uint32_t in_len,char* out,uint32_t out_len )

		//{
		//	int32_t ret = failed;
		//	iconv_t hIconv = iconv_open( to_code, from_code );
		//	if ( -1 == (int)hIconv )
		//	{
		//		return not_supported;
		//	}
		//	ret = iconv(hIconv,static_cast<const char**>(&in),&in_len,
		//		static_cast<char**>(&out),&out_len );
		//	iconv_close(hIconv);
		//	return ret;
		//}

		//std::string utf8_to_unicode(const char* in,uint32_t in_len)
		//{
		//	++in_len;
		//	wchar_t* out = new wchar_t[in_len];
		//	out[in_len] = 0;
		//	change_code("UTF-8","UCS-2-INTERNAL",in,in_len,(char*)(out),in_len*sizeof(wchar_t));
		//	std::string ret = wstring_to_string(std::wstring(out));
		//	delete []out;
		//	return ret;
		//}


		/*
		IP Address = 202.186.13.4
		w = 202, x = 186, y = 13 and z = 4

		INT IP Number = 16777216*202 + 65536*186 + 256*13 + 4
		= 3388997632 + 12189696 + 3328 + 4
		= 3401190660
		INT ---> IP:
		w = int ( IP Number / 16777216 ) % 256
		x = int ( IP Number / 65536 ) % 256
		y = int ( IP Number / 256 ) % 256
		z = int ( IP Number ) % 256
		*/


		std::string to_string(uint32 value)
		{
			return boost::lexical_cast<std::string>(value);
		}

		std::string int_to_ip(uint32 ip)
		{
			std::string ip_string = to_string(static_cast<uint32>(ip)%256);
			ip_string = ip_string + ".";
			ip_string = ip_string + to_string(static_cast<uint32>(ip/256)%256);
			ip_string = ip_string + ".";
			ip_string = ip_string + to_string(static_cast<uint32>(ip/65536)%256);
			ip_string = ip_string + ".";
			ip_string = ip_string + to_string(static_cast<uint32>(ip/16777216)%256);
			return ip_string;
		}



	}
}




#endif  // JELLY_SHARE_SRC_UTILITY_CONVERSION_H_
